# -*- coding: utf-8 -*-

import time
import functools

debug = False

def time_me(*args):
    def _time_me(fn):
        @functools.wraps(fn)
        def _wrapper(*args, **kwargs):
            start = time.time()
            result = fn(*args, **kwargs)
            if debug:
                print("%s  %s" % (fn.__name__, time.time() - start))
                print("func : %s, info:%s,  cost: %s" % (fn.__name__, fn, time.time() - start))
            return result

        return _wrapper

    return _time_me


def Tracer(old_class):
    class Wrapper:
        def __init__(self, *args, **kargs):
            self.wrapped = old_class(*args, **kargs)

        def __getattr__(self,attrname):
            #print('Trace:'+attrname)
            start = time.time()

            result = getattr(self.wrapped, attrname)
            #if time.time()-start >= 1:
            #    print("class : {0},  func : {1},  exec cost time  : {2}".format(old_class, attrname, time.time()-start))
            return result

    return Wrapper